L’ojectif est de savoir si avec ceratines fonction de imager, est possible de compter les cellules
# load image
papSmear <- load.image('papSmear.jpg')
papSmear
## Image. Width: 493 pix Height: 335 pix Depth: 1 Colour channels: 3
par(mfrow=c(1,2))
plot(papSmear)
plot(grayscale(papSmear))
Depth = 1 means the object is a static image and not video.
Clour channels = 3 means the image content Red, Green, Blue colours.
layout(t(1:2))
hist(papSmear)
hist(grayscale(papSmear))
hist function uses the values of the 3 channels rgb as a vector values. We can plot separately histograms by color
# for red
G(papSmear) %>% hist(main="Green channels values")
If we convert the image object’s to dataframe, we can view the value of each pixel.
layout(t(1:2))
as.data.frame(papSmear)
tail(as.data.frame(papSmear))
library(ggplot2)
papSeam_df <- as.data.frame(papSmear)
pap <- plyr::mutate(papSeam_df,channel=factor(cc,labels=c('R','G','B')))
ggplot(pap,aes(value,col=channel)) + geom_histogram(bins=30) + facet_wrap(~ channel)
papSmearg <- grayscale(papSmear)
f <- ecdf(papSmearg)
plot(f, main="Empirical CDF of luminance values (gray)")
gr <- imgradient(papSmear,"xy")
grG <- imgradient(grayscale(papSmear), "xy")
plot(gr, layout="row")
plot(grG, layout="row")
layout(t(1:2))
dx <- imgradient(papSmear,"x")
dy <- imgradient(papSmear,"y")
grad.mag <- sqrt(dx^2+dy^2)
plot(grad.mag,main="Gradient magnitude with color")
papSmear.G <- grayscale(papSmear)
dx.G <- imgradient(papSmear.G,"x")
dy.G <- imgradient(papSmear.G,"y")
grad.mag.G <- sqrt(dx.G^2+dy.G^2)
plot(grad.mag.G ,main="Gradient magnitude with gray")
l <- imgradient(papSmear,"x")
as.data.frame(l)
dim(l)
## [1] 493 335 1 3
par(mfrow=c(1,2))
plot(imhessian(papSmear)[2])
plot(with(imhessian(papSmear),(xx*yy - xy^2)), main="Determinant of Hessian")
layout(t(1:2))
threshold(papSmear,"99%") %>% plot(main="Determinant: 1% highest values (raw) ")
threshold(with(imhessian(papSmear),(xx*yy - xy^2)),"99%") %>% plot(main="Determinant: 1% highest values")
threshold(grad.mag, "99%") %>% plot(main="Determinant: 1% highest values (gradient)")
lab1 <- threshold(grad.mag, "99%") %>% label
lab2 <- threshold(with(imhessian(papSmear),(xx*yy - xy^2)), "99%") %>% label
par(mfrow=c(1,2))
plot(lab1, main= "Labelled regions from gradient")
plot(lab2, main= "Labelled regions from scare")
class(lab1)
## [1] "cimg" "imager_array" "numeric"
lab1
## Image. Width: 493 pix Height: 335 pix Depth: 1 Colour channels: 3
df1 <- as.data.frame(lab1) %>% subset(value>0)
df2 <- as.data.frame(lab2) %>% subset(value>0)
head(df2,3)
par(mfrow=c(1,2))
centers1 <- dplyr::group_by(df1,value) %>% dplyr::summarise(mx=mean(x),my=mean(y))
plot(lab1)
with(centers1, points(mx, my, col="yellow"))
centers2 <- dplyr::group_by(df2,value) %>% dplyr::summarise(mx=mean(x),my=mean(y))
plot(lab2)
with(centers2, points(mx, my, col="red"))
get.centers <- function(im,thr="99%")
{ im <- isoblur(im,5)
dt <- imhessian(im) %$% { xx*yy - xy^2 } %>% threshold(thr) %>% label
as.data.frame(dt) %>% subset(value>0) %>% dplyr::group_by(value) %>% dplyr::summarise(mx=mean(x),my=mean(y))
}
par(mfrow=c(1,2))
plot(lab1)
get.centers(lab1,"50%") %$% points(mx,my,col="yellow")
plot(grad.mag,main="Gradient magnitude with color")
Cette méthode ne permet pas de compter les cellules.